package main

import "fmt"

type md struct {
	sum       int     //结果
	max_ascii int     //最大ascii
	min_ascii int     //最小ascii
	cycle     int     //周期
	result    [][]int //保存结果
}

func New(sum int, max_ascii int, min_ascii int, cycle int) *md {
	return &md{
		sum:       sum,
		max_ascii: max_ascii,
		min_ascii: min_ascii,
		cycle:     cycle,
		result:    make([][]int, 0),
	}
}

func (md *md) Do() [][]int {
	//sum=系数*a1+系数*a2...+系数*an
	//1、先确定man_n项和min_n是？
	min_n := 1
	for {
		if md.max_ascii*(1+min_n*md.cycle+1)*min_n/2 >= md.sum {
			break
		}
		min_n++
	}

	max_n := 1
	for {
		if md.min_ascii*(1+max_n*md.cycle+1)*max_n/2 >= md.sum {
			break
		}
		max_n++
	}

	//s(md.sum, "最少项:", min_n, "最多项：", max_n)

	//2、从低到高位，逐级确认是系数
	for n := min_n; n <= max_n; n++ {
		xs := make([]int, n)
		if md.guess(xs, n, 0) {
			//break
		}
	}

	return md.result
}

//xs 系数
//n 最多位数
//nth 当前位数
func (md *md) guess(xs []int, n int, nth int) bool {
	for i := md.min_ascii; i <= md.max_ascii; i++ {
		xs[nth] = i
		//优先填满
		if nth+1 < n {
			md.guess(xs, n, nth+1)
		}
		//填满后再比较
		if nth == n-1 {
			ret := md.check(xs)
			if ret >= 0 {
				break
			}
		}
	}

	return false
}

//前n项和
//0==,1>,-1<
func (md *md) check(xs []int) int {
	sum2 := 0
	for i := 0; i < len(xs); i++ {
		sum2 += xs[i] * (md.cycle*i + 1)
	}
	if sum2 == md.sum {
		md.save(xs)
		return 0
	} else if sum2 > md.sum {
		return 1
	}

	return -1
}

func (md *md) save(xs []int) {
	xs2 := make([]int, len(xs))
	for k, v := range xs {
		xs2[k] = v
	}

	md.result = append(md.result, xs2)
}

func main() {
	mm := New(3037, 126, 32, 29)
	result := mm.Do()

	for _, v := range result {
		str := make([]byte, len(v))
		for k, v2 := range v {
			str[k] = byte(v2)
		}
		s(v, string(str))
	}
}

func s(a ...interface{}) {
	fmt.Println(a...)
}
